//
//  CustomCalloutView.m
//  ConvenientlyTake
//
//  Created by 张奇 on 2023/1/10.
//

#import "CustomCalloutView.h"
#define kArrorHeight        10
#define kPortraitMargin     5
#define kPortraitWidth      (45-kPortraitMargin*2)
#define kPortraitHeight     (45-kPortraitMargin*2)

#define kTitleWidth         (145-kPortraitHeight-kPortraitMargin*2)
#define kTitleHeight        20

@interface CustomCalloutView ()

@property (nonatomic, strong) UIImageView *portraitView;
@property (nonatomic, strong) UILabel *subtitleLabel;
@property (nonatomic, strong) UILabel *titleLabel;

@end

@implementation CustomCalloutView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.backgroundColor = UIColorForBackground;
        [self initSubViews];
    }
    return self;
}

- (void)initSubViews
{
    // 添加图片，即商户图
    self.portraitView = [[UIImageView alloc] initWithFrame:CGRectMake(kPortraitMargin, kPortraitMargin, kPortraitWidth, kPortraitHeight)];
    self.portraitView.layer.cornerRadius = kPortraitHeight/2.0;
    self.portraitView.layer.masksToBounds = YES;
    self.portraitView.backgroundColor = [UIColor blackColor];
    [self addSubview:self.portraitView];
    
    // 添加标题，即商户名
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(kPortraitMargin * 2 + kPortraitWidth, kPortraitMargin, kTitleWidth, kTitleHeight)];
    self.titleLabel.font = [UIFont boldSystemFontOfSize:13];
    self.titleLabel.textColor = [UIColor blackColor];
    self.titleLabel.text = @"titletitletitletitle";
    [self addSubview:self.titleLabel];
    
    // 添加副标题，即商户地址
    self.subtitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(kPortraitMargin * 2 + kPortraitWidth, 2+kTitleHeight, kTitleWidth, kTitleHeight)];
    self.subtitleLabel.font = [UIFont systemFontOfSize:13];
    self.subtitleLabel.textColor = [UIColor lightGrayColor];
    self.subtitleLabel.text = @"subtitleLabelsubtitleLabelsubtitleLabel";
    [self addSubview:self.subtitleLabel];
}

- (void)setTitle:(NSString *)title {
    self.titleLabel.text = title;
}

- (void)setSubtitle:(NSString *)subtitle {
    self.subtitleLabel.text = subtitle;
}

- (void)setImage:(UIImage *)image {
    self.portraitView.image = image;
}


- (void)drawRect:(CGRect)rect
{
   
//   [self drawInContext:UIGraphicsGetCurrentContext()];
//
//   self.layer.shadowColor = [[UIColor blackColor] CGColor];
//   self.layer.shadowOpacity = 1.0;
//   self.layer.shadowOffset = CGSizeMake(0.0f, 0.0f);
   
    self.layer.borderWidth = 0.5;
    self.layer.borderColor = CellSeprealColor.CGColor;
    self.layer.cornerRadius = self.height/2.0;
    self.layer.masksToBounds = YES;
    
}

//- (void)drawInContext:(CGContextRef)context
//{
//
//   CGContextSetLineWidth(context, 2.0);
//   CGContextSetFillColorWithColor(context, [UIColor colorWithRed:0.3 green:0.3 blue:0.3 alpha:0.8].CGColor);
//
//   [self getDrawPath:context];
//   CGContextFillPath(context);
//
//}

//- (void)getDrawPath:(CGContextRef)context
//{
//   CGRect rrect = self.bounds;
//   CGFloat radius = 6.0;
//   CGFloat minx = CGRectGetMinX(rrect),
//   midx = CGRectGetMidX(rrect),
//   maxx = CGRectGetMaxX(rrect);
//   CGFloat miny = CGRectGetMinY(rrect),
//   maxy = CGRectGetMaxY(rrect)-kArrorHeight;
//
//   CGContextMoveToPoint(context, midx+kArrorHeight, maxy);
//   CGContextAddLineToPoint(context,midx, maxy+kArrorHeight);
//   CGContextAddLineToPoint(context,midx-kArrorHeight, maxy);
//
//   CGContextAddArcToPoint(context, minx, maxy, minx, miny, radius);
//   CGContextAddArcToPoint(context, minx, minx, maxx, miny, radius);
//   CGContextAddArcToPoint(context, maxx, miny, maxx, maxx, radius);
//   CGContextAddArcToPoint(context, maxx, maxy, midx, maxy, radius);
//   CGContextClosePath(context);
//}

@end
